﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using M7;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media.Imaging;
using System.IO;

namespace C7
{
    public static class Info
    {
        public static IPAddress ServerIP = IPAddress.Parse(Properties.Settings.Default.ServerIP);
        public static int serverPort = Properties.Settings.Default.ServerPort;

        public static CurrentInfo current = new CurrentInfo(Properties.Settings.Default.TableID, Info.GetLocalIP(), Properties.Settings.Default.Port);

        public static BitmapImage ArrayToImage(byte[] data)
        {
            MemoryStream strm = new MemoryStream();

            strm.Write(data, 0, data.Length);

            strm.Position = 0;

            System.Drawing.Image img = System.Drawing.Image.FromStream(strm);

            BitmapImage bi = new BitmapImage();

            bi.BeginInit();

            MemoryStream ms = new MemoryStream();

            img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

            ms.Seek(0, SeekOrigin.Begin);

            bi.StreamSource = ms;

            bi.EndInit();

            return bi;
        }
        public static System.Windows.UIElement module;
        public static Panel messagePanel;
        public static StackPanel UsersPanel;

        public static NSong CurrentSong = new NSong("Unkown", "Unkown", "Unknown", "No Lyrics available", "Unkown");

        public static MainWindow window;

        public static IPAddress GetLocalIP()
        {
            string pcname = Dns.GetHostName();
            IPAddress[] ips = Dns.GetHostAddresses(pcname);
            var IPs = from ip in ips
                      where ip.ToString().StartsWith("192")
                      select ip;
            if (IPs.ToList().Count.Equals(0))
            {
                return null;
            }
            else
            {
                return IPs.ToList()[0];
            }
        }
    }
}